package pe.com.rix.taglib.view;




import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

import pe.com.cineplanet.bean.cineplanet.Constantes;
import pe.com.rix.taglib.bean.menu.MenuItem;


public class Menu extends BodyTagSupport{

	private static final long serialVersionUID = 1L;
	private MenuItem menuRoot;
	
	@Override
	public int doAfterBody() throws JspException {
	
		BodyContent bodycontent = getBodyContent();
        String body = bodycontent.getString();
        
		StringBuffer html = new StringBuffer("<ul id='menuToolbar' style='display:none'>");
		
		if(getMenuRoot()==null){
			
			MenuItem m = new MenuItem();
			m.setValues(Constantes.formatMenu(Constantes.defaultMenu()));
			MenuItem.doHtml(m.getItems(), html);
			
		}else
		{
			MenuItem.doHtml(getMenuRoot().getItems(), html);
		}
		
		
		
		html.append(body);
      		
		html.append("</ul>");
		
		
		JspWriter out = bodycontent.getEnclosingWriter();
		try {
			out.print(html.toString());
		} catch (java.io.IOException ex) {
			throw new JspException(ex.getMessage());
		}
		return SKIP_BODY;
	}
	
	
	
	
	
	public MenuItem getMenuRoot() {
		return menuRoot;
	}
	
	public void setMenuRoot(MenuItem menuRoot) {
		this.menuRoot = menuRoot;
	}
	
}
